package com.leetcode.No0171;

import org.junit.Test;

/**
 * @program: leetcode
 * @description: Excel表列序号
 * @author: wangzhihua
 * @date: 2021-07-30
 */
public class Solution01 {

	@Test
	public void getPowerOfSixteen() {
		int h = 0;
		int rtn = 1;
		System.out.print("[" + rtn + ", ");
		while (h <= 6) {
			rtn *= 26;
			++h;
			System.out.print(rtn + ", ");
		}
		System.out.println(rtn * 26 + "]");
	}

	@Test
	public void test01() {
		System.out.println(titleToNumber("FXSHRXW"));
	}

	public int titleToNumber(String columnTitle) {
		int ans = 0;
		int len = columnTitle.length();
		// 16的幂
		int[] powerOf26 = new int[]{1, 26, 676, 17576, 456976, 11881376, 308915776};
		for (int i = len - 1; i >= 0; --i) {
			ans += (columnTitle.charAt(i) - 'A' + 1) * powerOf26[len - i - 1];
		}
		return ans;
	}

}
